package com.gec.mall.service.impl;

import com.gec.mall.mapper.TbTypeTemplateMapper;
import com.gec.mall.pojo.TbTypeTemplate;
import com.gec.mall.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @Author: li
 * @Date: 2023/2/2
 * @PACKAGE_NAME:com.gec.mall.service.impl
 * @Project_Name:mall-parent
 * @VERSION: 1.0.0
 */
@Service
public class TemplateServiceImpl implements TemplateService {

    @Autowired
    private TbTypeTemplateMapper templateMapper;

    @Override
    public List<TbTypeTemplate> getAllTemplate() {
        return templateMapper.selectByExample(null);
    }

    @Override
    public TbTypeTemplate getTemplateById(Long id) {
        return templateMapper.selectByPrimaryKey(id);
    }

    @Override
    public void TemplateSaveOrUpdate(TbTypeTemplate template) {
        if (ObjectUtils.isEmpty(template.getId())){
            templateMapper.insert(template);
        }else {
            templateMapper.updateByPrimaryKey(template);
        }
    }


    @Override
    public void TemplateDelById(Long id) {
        templateMapper.deleteByPrimaryKey(id);
    }
}
